package com.bw.base.net

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class RetrofitUtils {
    companion object{
        val httpClient by lazy {
            OkHttpClient.Builder()
                .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                .addInterceptor {
                    val token=SPUtils.getInstance().getString("token")
                    val request=it.request().newBuilder()
                        .addHeader("token",token)
                        .addHeader("accessId","f73f232513264ddd9a4110292e3967a1")
                        .build()
                    return@addInterceptor it.proceed(request)
                }.build()
        }
        val retrofit by lazy {
            Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .client(httpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
        }
    }
}